package com.mayisoftware.mayioa.business.staff.impl.controller;



import com.mayisoftware.mayioa.business.staff.api.domain.StaffManagerAmendInfo;
import com.mayisoftware.mayioa.business.staff.api.domain.StaffManagerInfo;
import com.mayisoftware.mayioa.business.staff.api.domain.StaffManagerSearchInfo;
import com.mayisoftware.mayioa.business.staff.api.service.IStaffManagerViewService;
import com.mayisoftware.mayioa.common.api.annotation.Log;
import com.mayisoftware.mayioa.common.api.base.AjaxResult;
import com.mayisoftware.mayioa.common.api.enums.BusinessType;
import com.mayisoftware.mayioa.platform.impl.web.base.BaseController;
import com.mayisoftware.mayioa.platform.impl.web.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/staffmanager/list")
public class StaffManagerViewController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(StaffManagerViewController.class);
    private String prefix = "staffmanager/list";

    @Autowired
    private IStaffManagerViewService smvService;



    @RequiresPermissions("staffmanager:list:view")      //调包
    @GetMapping()
    public String staff() {
        return prefix + "/staffmanager";     //html文件名
    }

    @RequiresPermissions("staffmanager:list:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StaffManagerSearchInfo searchInfo) {
        startPage();
        List<StaffManagerInfo> list = smvService.getStaffManagerInfos(searchInfo);
        return getDataTable(list);
    }


    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("staffManagerInfo", smvService.getStaffManagerInfo(id));
        return prefix + "/edit";
    }


    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/manageradd";
    }

    /**
     * 增加信息
     */
    @RequiresPermissions("staffmanager:list:manageradd")
    @Log(title = "人员管理信息", businessType = BusinessType.INSERT)
    @PostMapping("/manageradd")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult addSave(StaffManagerAmendInfo staffManagerAmendInfo)
    {
        int records = 0;
        try{
            records = smvService.insertStaffManagerAmend(staffManagerAmendInfo);

        }catch (Exception ex){
            return toAjax(0);
        }

        return  toAjax(records);

    }
    /**
     * 修改信息
     */
    @RequiresPermissions("staffmanager:list:edit")
    @Log(title = "人员管理信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult editSave(StaffManagerAmendInfo staffManagerAmendInfo)
    {
        int records = 0;
        try{
//            hcMonitorInfo.setHcId(hcId);
//            hcService.updateHCMonitor(hcMonitorInfo);

            records = smvService.updateStaffManagerAmend(staffManagerAmendInfo);

        }catch (Exception ex){
            return toAjax(0);
        }

        return  toAjax(records);

    }
    /**
     * 删除信息
     */


    @RequiresPermissions("staffmanager:list:remove")
    @Log(title = "人员管理信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(smvService.removeStaffManager(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }


    @RequiresPermissions("staffmanager:list:removeAll")
    @Log(title = "人员管理信息", businessType = BusinessType.DELETE)
    @PostMapping("/removeAll")
    @ResponseBody
    public AjaxResult removeAll(String ids)
    {
        try
        {
            return toAjax(smvService.removeAllStaffManager(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }






}
